package thread.threadPool;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class Test {
    public static void main(String[] args) throws InterruptedException {
        ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(3, 6, 3, TimeUnit.SECONDS,
                new ArrayBlockingQueue<>(200),
                new ThreadPoolExecutor.CallerRunsPolicy());
        threadPoolExecutor.execute(new Runnable() {
            @Override
            public void run() {
                System.out.println(1);
            }
        });
    }
}

class Test4 {
    public static void main(String[] args) {
        ThreadPoolExecutor executor = new ThreadPoolExecutor(4, 10,
                1, TimeUnit.SECONDS, new LinkedBlockingDeque<>(40),
                new ThreadPoolExecutor.CallerRunsPolicy());
        List<Integer> list = new ArrayList<>(50);
        for (int i = 0; i < 50 ; i++) {
            list.add(i);
        }
        // 利用线程池 实现多线程 打印List中的每个 元素
        for (Integer integer : list) {
            MyRunnableTask2 myRunnableTask2 = new MyRunnableTask2(integer);
            executor.execute(myRunnableTask2);
        }
        System.out.print(" Main-over ");
    }
}
class MyRunnableTask2 implements Runnable {
    Integer obj;
    public MyRunnableTask2(Integer obj) {
        this.obj = obj;
    }
    @Override
    public void run() {
        System.out.print(obj+" ");
    }
}


class TestWait {
    public static void main(String[] args) {
        String s  = "abc";
        synchronized (s) {
            s.notify();
        }
    }
}
